package com.it.service.impl;

import com.it.mapper.UsersMapper;
import com.it.pojo.PageBean;
import com.it.pojo.User;
import com.it.service.UserService;
import com.it.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;

    @Override
    public PageBean<User> list(Integer pageNum, Integer pageSize) {
        // 计算总记录数
        Long total = usersMapper.count();

        // 计算偏移量
        Integer offset = (pageNum - 1) * pageSize;

        // 查询当前页数据
        List<User> records = usersMapper.list(offset, pageSize);

        // 封装分页结果（使用 setItems 而非 setRecords）
        PageBean<User> pageBean = new PageBean<>();
        pageBean.setTotal(total);
        pageBean.setItems(records); // 关键修改：使用 setItems

        return pageBean;
    }

    @Override
    public void deleteusers(Integer id) {
        usersMapper.deleteusers(id);
    }
}
